define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'car_order/index' + location.search,
                    add_url: 'car_order/add',
                    edit_url: 'car_order/edit',
                    del_url: 'car_order/del',
                    multi_url: 'car_order/multi',
                    import_url: 'car_order/import',
                    table: 'car_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible: true,// 默认显示搜索条件
                search: false,// 搜索框
                commonSearch: false,// 搜索按钮
                showToggle: false,// 切换视图
                showColumns: false,// 显示列
                showExport: false,// 导出按钮
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('发布用户'), operate: 'LIKE', formatter:function(value,row,index){
                                var html='';
                                html = '('+row.user_id+')'+value;
                                return html;
                            }},
                        {field: 'brand_id', title: __('Brand_id'), visible:false},
                        {field: 'brand.name', title: __('Brand_id'), operate:false},
                        {field: 'series_id', title: __('Series_id'), visible:false},
                        {field: 'series.name', title: __('Series_id'), operate:false},
                        {field: 'model_id', title: __('Model_id'), visible:false},
                        {field: 'model.name', title: __('Model_id'), operate:false},
                        // {field: 'category', title: __('Category'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'licensing_time', title: __('Licensing_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'kilometer', title: __('Kilometer'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_fire', title: __('Is_fire'), formatter: Table.api.formatter.label, searchList: {0: __('否'), 1: __('是')}},
                        {field: 'is_blisters', title: __('Is_blisters'), formatter: Table.api.formatter.label, searchList: {0: __('否'), 1: __('是')}},
                        {field: 'is_incident', title: __('Is_incident'), formatter: Table.api.formatter.label, searchList: {0: __('否'), 1: __('是')}},
                        {field: 'province.name', title: __('所在区域'), formatter:function(value,row,index){
                                var html='';
                                html = row.province.name + '/' + row.city.name + '/' + row.area.name;
                                return html;
                            }},
                        // {field: 'province_id', title: __('Province_id')},
                        // {field: 'city_id', title: __('City_id')},
                        // {field: 'area_id', title: __('Area_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'exterior', title: __('外观'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'glass', title: __('玻璃'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'lights', title: __('车灯'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'wheel', title: __('轮胎'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'interior', title: __('内饰'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'internal_function', title: __('内部功能'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'nacelle', title: __('机舱'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'motor', title: __('发动机'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        {field: 'gearbox', title: __('变速箱'), events: Table.api.events.image, formatter: Table.api.formatter.images, operate: false},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: {0: __('销售中'), 1: __('已销售'), 2: __('已取消'), 100: __('已下架')}},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
